package com.bleeth.fx.demo1;

import com.bleeth.fx.helper.ControlsHelper;
import com.bleeth.fx.layout.FormBuilder;
import com.bleeth.fx.layout.GirdCell;
import com.bleeth.fx.meta.IForm;
import com.bleeth.fx.meta.View;
import com.bleeth.fx.meta.ViewRouter;
import javafx.beans.property.Property;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@View(value = "/", type = "begin")
public class Demo1 implements IForm {


    @Override
    public Region make(Property... properties) {
        TextField username = ControlsHelper.createTextField("admin", "", "", "");
        TextField password = ControlsHelper.createPasswordField("123456");
        Button loginBtn = ControlsHelper.createBtn("admin", "", "");


        VBox mainBox = FormBuilder.form(500D, 500D)
                .addEmptyRow(10D)
                .addRow(GirdCell.createCell(1, Pos.CENTER,10))
                .addCell(0, username)
                .addCell(0, loginBtn)
                .addCell(0, password)
                .endRow(true)
                .build();

        loginBtn.setOnAction(event -> {
            Region loginBox =  ViewRouter.builder().push("login", username.textProperty(), password.textProperty());
            FormBuilder.RowBuilder loginBoxRowBuilder = FormBuilder.queryForm(mainBox).queryRowByCell("loginBox");
            if (loginBoxRowBuilder == null) {
                FormBuilder.queryForm(mainBox)
                        .addEmptyRow(20D)
                        .addRow(GirdCell.createCell(1, Pos.CENTER))
                        .addCell(0, loginBox,"loginBox");
            }

        });
        return mainBox;
    }


    @Override
    public void css() {
        //css加载
    }


}
